class Designation < ActiveRecord::Base
  belongs_to :project
  belongs_to :user
  
  accepts_nested_attributes_for :user
  
  named_scope :administrators, :conditions => {:admin => true}
  
  validates_uniqueness_of :user_id, :scope => :project_id
  
  after_create :send_invitation_email
  
  def send_invitation_email
    Delayed::Job.enqueue InvitationMailerJob.new(Thread.current[:user_id], user_id, project_id) if Thread.current[:user_id] != user_id
  end  
end